package leetcode.code1218;

public class Solution extends Solution1218 {

	private final int OFF = (int) 10e4;// 矫正负数
	private final int SIZE = OFF * 2 + 1;// 数组长度


	@Override
	public int longestSubsequence(int[] arr, int difference) {
		int[] hash = new int[SIZE];
		int ans = 0;
		for (int element : arr) {
			int cur = element; // 当前数
			int find = cur - difference; // cur的左侧序列数
			int size = hash[find + OFF] + 1; // find的长度+1是cur的长度
			hash[cur + OFF] = size;
			ans = Math.max(ans, size);// 更新最长子序列
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();

	}

}
